import {handlerGobackClick} from "../../../utils/util";
import {Subscribe} from "../../../models/subscribe";

const subscribe = new Subscribe()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        showBtn: false,
        id: '',
        details:{},
        status:{
            0:'未处理',
            1:'已同意',
            2:'已拒绝',
            3:'已失效',
            4:'已过期',
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (options.id) {
            this.setData({
                id: options.id
            })
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },
    onShow() {
        this.initPageData()
    },
    againAudit(){
        this.setData({
            showBtn: !this.data.showBtn
        })
    },
    hanlderAudit(e) {
        let status = e.currentTarget.dataset.status
        subscribe.auditProcess(this.data.id,status)
            .then((res)=>{
                this.setData({
                    showBtn: !this.data.showBtn
                })
                this.initPageData()
            })
            .catch((err)=>{
                console.log(err);})
    },
    handlerGobackClick,
    initPageData() {
        subscribe.auditListById(this.data.id)
            .then((res) => {
                this.setData({
                  details: res.result,
                  showBtn: res.result.status === 0 ? false : true,
                });
            })
            .catch((err) => {
                console.log(err);
            })
    }
})
